using UnityEngine;

public class EnemyDamager : MonoBehaviour
{
    [Header("Damage Settings")]
    [SerializeField] private LayerMask playerLayer;
    [SerializeField] private int damage;
    [SerializeField] private float damageInterval;

    private float nextDamageTime;

    private void OnTriggerStay(Collider other)
    {
        if (Time.time < nextDamageTime)
            return;

        if (((1 << other.gameObject.layer) & playerLayer) != 0 &&
            other.CompareTag("Player"))
        {
            PlayerDamager playerDamager = other.GetComponent<PlayerDamager>();
            if (playerDamager != null)
            {
                playerDamager.TakeDamage(damage);
                nextDamageTime = Time.time + damageInterval;
            }
        }
    }
}
